package org.ns.longhttp.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class DataEntry {
    private Long id;
    private String mtype;
    private Object content;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getMtype() {
        return mtype;
    }

    public void setMtype(String mtype) {
        this.mtype = mtype;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }

    public String contentString() {
        if (content == null) {
            return null;
        }

        return String.valueOf(content);
    }

    public <T> T parseObject(Class<T> type) {
        if (content == null) {
            return null;
        }
        if (content instanceof JSONObject) {
            return ((JSONObject) content).toJavaObject(type);
        }
        String contentString = contentString();
        return JSON.parseObject(contentString, type);
    }
}
